package com.ruoyi.fault.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fault.domain.FaultAssign;
import com.ruoyi.fault.service.IFaultAssignService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修人员分配Controller
 * 
 * @author silence
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/fault/assign")
public class FaultAssignController extends BaseController
{
    @Autowired
    private IFaultAssignService faultAssignService;

    /**
     * 查询维修人员分配列表
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultAssign faultAssign)
    {
        startPage();
        List<FaultAssign> list = faultAssignService.selectFaultAssignList(faultAssign);
        return getDataTable(list);
    }

    /**
     * 导出维修人员分配列表
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:export')")
    @Log(title = "维修人员分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultAssign faultAssign)
    {
        List<FaultAssign> list = faultAssignService.selectFaultAssignList(faultAssign);
        ExcelUtil<FaultAssign> util = new ExcelUtil<FaultAssign>(FaultAssign.class);
        util.exportExcel(response, list, "维修人员分配数据");
    }

    /**
     * 获取维修人员分配详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultAssignService.selectFaultAssignById(id));
    }

    /**
     * 新增维修人员分配
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:add')")
    @Log(title = "维修人员分配", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultAssign faultAssign)
    {
        return toAjax(faultAssignService.insertFaultAssign(faultAssign));
    }

    /**
     * 修改维修人员分配
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:edit')")
    @Log(title = "维修人员分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultAssign faultAssign)
    {
        return toAjax(faultAssignService.updateFaultAssign(faultAssign));
    }

    /**
     * 删除维修人员分配
     */
    @PreAuthorize("@ss.hasPermi('fault:assign:remove')")
    @Log(title = "维修人员分配", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultAssignService.deleteFaultAssignByIds(ids));
    }
}
